<html>
<head><meta charset="utf-8"><title>forcing loop miscompilation · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html">forcing loop miscompilation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223129283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223129283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223129283">(Jan 18 2021 at 14:55)</a>:</h4>
<p>In <a href="https://github.com/rust-lang/rust/pull/77972">https://github.com/rust-lang/rust/pull/77972</a>, <span class="user-mention" data-user-id="116122">@simulacrum</span> fixed the most trivial cases of <code>loop {}</code> miscompiling. We already had <a href="https://github.com/rust-lang/rust/issues/28728#issuecomment-637880180">some incidental fixes due to MIR optimization</a> which meant that we needed a closure to cause the miscompilation. What's the next-most simple way of causing UB to be triggered?</p>



<a name="223129456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223129456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223129456">(Jan 18 2021 at 14:56)</a>:</h4>
<p>Anything placed inside the loop which will split into two bb's will cause the fix to not fire</p>



<a name="223129474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223129474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223129474">(Jan 18 2021 at 14:56)</a>:</h4>
<p>e.g., I imagine an assert or call of any kind</p>



<a name="223129518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223129518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223129518">(Jan 18 2021 at 14:57)</a>:</h4>
<p>self-recursive function calls are entirely not targeted right now and also cause the problem</p>



<a name="223129931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223129931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223129931">(Jan 18 2021 at 15:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/forcing.20loop.20miscompilation/near/223129518">said</a>:</p>
<blockquote>
<p>self-recursive function calls are entirely not targeted right now and also cause the problem</p>
</blockquote>
<p>I actually tried that first, but the trivial ones are not UB:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[inline(never)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">oops</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">oops</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="223130107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130107">(Jan 18 2021 at 15:00)</a>:</h4>
<p>Won't self recursive functions stack overflow even if they're not unsound?</p>



<a name="223130195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130195">(Jan 18 2021 at 15:01)</a>:</h4>
<p>LLVM will replace those with just unreachable (i.e. UB).</p>



<a name="223130366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130366">(Jan 18 2021 at 15:01)</a>:</h4>
<p>For <code>loop {}</code> to miscompile, you need to have a side-effect free <code>loop {}</code> in a function and call that function.</p>



<a name="223130393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130393">(Jan 18 2021 at 15:01)</a>:</h4>
<p>the miscompile will be observable in the callee.</p>



<a name="223130612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130612">(Jan 18 2021 at 15:02)</a>:</h4>
<p>asserts in particular will be considered to be side-effectful, so that won't help to repro in any way.</p>



<a name="223130697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130697">(Jan 18 2021 at 15:03)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">oops</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="o">||</span><span class="w"> </span><span class="k">loop</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">drop</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">})()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="223130720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130720">(Jan 18 2021 at 15:03)</a>:</h4>
<p>seems to trigger</p>



<a name="223130921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223130921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223130921">(Jan 18 2021 at 15:05)</a>:</h4>
<p><a href="https://rust.godbolt.org/z/bW9WsE">https://rust.godbolt.org/z/bW9WsE</a> another way to do it.</p>



<a name="223163978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/forcing%20loop%20miscompilation/near/223163978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/forcing.20loop.20miscompilation.html#223163978">(Jan 18 2021 at 21:08)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> I appreciate your fruit examples <span aria-label="love" class="emoji emoji-2764" role="img" title="love">:love:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>